package cn.edu.sdjzu.xg.eagle.mapper;

import cn.edu.sdjzu.xg.eagle.entities.Statistics;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface StatisticsMapper {

    @Insert("INSERT INTO Statistics (statistic_time, statistic_amount, statistics_type) " +
            "VALUES (#{statisticTime}, #{statisticAmount}, #{statisticsType})")
    @Options(useGeneratedKeys = true, keyProperty = "statisticId", keyColumn = "statistic_id")
    boolean addStatistic(Statistics statistic);

    @Delete("DELETE FROM Statistics WHERE statistic_id = #{statisticId}")
    boolean deleteStatistic(Integer statisticId);

    @Update("UPDATE Statistics SET " +
            "statistic_time = #{statisticTime}, " +
            "statistic_amount = #{statisticAmount}, " +
            "statistics_type = #{statisticsType} " +
            "WHERE statistic_id = #{statisticId}")
    boolean updateStatistic(Statistics statistic);

    @Select("SELECT * FROM Statistics WHERE statistic_id = #{statisticId}")
    Statistics findStatisticById(Integer statisticId);

    @Select("SELECT * FROM Statistics")
    List<Statistics> findAllStatistics();
}